<?php
/**
 * Created by PhpStorm.
 * User: xiaoxin
 * Date: 2018/11/15 0015
 * Time: 10:35
 */

namespace app\admin\controller;
use think\Controller;
use think\Db;

class Common extends Controller
{
	public function _initialize(){
		return true;
		$res = Db::name('auth_role_admin')
			->field('t2.role_rule')
			->alias('t1')
			->join('auth_role t2','t1.role_id = t2.role_id')
			->where('t1.admin_id',session('admin_id'))
			->select();
		if (!$res){
			return false;
		}
		$str = [];
		foreach ( $res as $row ) {
			$str=array_merge($str,explode(',', $row['role_rule']));
		}
		$str = array_unique($str);
		$rule = Db::name('auth_rule')->where('rule_id','in',$str)->column('role_rule');
		$url = request()->module().'/'.request()->controller().'/'.request()->action();
		$url = strtolower($url);
		$ruleList = [];
		foreach ( $rule as $item ) {
			$ruleList[] = strtolower($item);
		}
		if(in_array($url,$ruleList)){
			return true;
		}else{
			echo '<script>alert("你没有权限")</script>';exit();
		}
	}
}